package com.wanmait.computershop.dao;

import com.wanmait.computershop.util.DBhelper;
import com.wanmait.computershop.vo.CateGory;
import com.wanmait.computershop.vo.Product;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class WebSearchDao {
    //根据内容模糊查询
    public List<Product> findProductsBySearch(String search){
        QueryRunner queryRunner = new QueryRunner(DBHelper.getDruidDataSource());
        String sql = "SELECT * FROM product WHERE title LIKE concat('%',?,'%')";
        try {
            List<Product> productList  = queryRunner.query(sql,new BeanListHandler<>(Product.class),search);
            return productList;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }
}
